<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require DOCMENT_ROOT."/Framework/controller.class.php";
class userController extends controller{
    public function __construct(){
     parent::header();
     parent::smartyAction("index");
        
    }
    
    public function register(){
        $this->smarty->display("register.html");    
    }
    public function list1(){
        $page = isset($_GET["page"])?$_GET["page"]: 1;
        $num=2;

        $start = ($page-1)*$num;
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $arr = $this->usermodel ->userList("id asc",$num,$start);
        $count = $this->usermodel ->userCount();
        //总页数
        $pageCount = ceil($count/$num);
        //调取展示页面
        $this ->smarty->assign("list1", $arr);
        $this ->smarty->assign("page", $page);
        $this ->smarty->assign("pagecount", $pageCount);
        $this ->smarty->display("list1.html");
    } 
     public function list2(){
        $page = isset($_GET["page"])?$_GET["page"]: 1;
        $num=2;

        $start = ($page-1)*$num;
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $arr =$usermodel->userList2("id asc",$num,$start);
        $count =$usermodel->userCount2();
        //总页数
        $pageCount = ceil($count/$num);
        //调取展示页面
        $this ->smarty->assign("list2", $arr);
        $this ->smarty->assign("page", $page);
        $this ->smarty->assign("pagecount", $pageCount);
        $this ->smarty->display("xq.html");
    } 
    public function index(){
        $this ->smarty->display("index.html");
    }
     public function fatie(){
        $this ->smarty->display("fatie.html");
    }
    public function content(){
        $this ->smarty->display("content.html");
    }
     public function checkDenglu(){        
        $name=$_GET["name"];
        $pwd=$_GET["pwd"]; 
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $arr=$usermodel->denglu($name,$pwd);
//        $_SESSION["id"]=$arr["id"];
        if(empty($arr)){
            echo false;
        }else{
            echo true;
        }
    }
    public function addUser(){
        $name= $_POST["name"];
        $pwd=$_POST["pwd"];
        $nick_name=$_POST["nick_name"];
        $email=$_POST["email"];
        $tel=$_POST["tel"];
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $result = $this->usermodel ->addUser($name,$pwd,$nick_name,$email,$tel);
        echo $result;
    }
        public function addUser1(){
        $id= $_POST["id"];
        $title=$_POST["title"];
        $content=$_POST["content"];
        $add_time=$_POST["add_time"];
        $click=$_POST["click"];
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $result = $this->usermodel ->addUser1($id,$title,$content,$add_time,$click);
        echo $result;
    }
    public function delete(){
        $id=$_GET["id"];
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $result =$this->usermodel ->delete($id);
        echo $result;

    }
    public function update(){
            $id = $_GET["id"];
            $pwd = $_GET["pwd"];
            $email = $_GET["email"];
            $tel = $_GET["tel"];
            require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
            $usermodel= new usermodel();
            $res =  $this->usermodel ->userUpdate($id,$pwd,$email,$tel);
            echo $res;
    }
    public function updates(){
        $id =$_GET["id"];
        require DOCMENT_ROOT."/index/model/usermodel.class.php"; 
        $usermodel= new usermodel();
        $arr =  $this->usermodel ->select($id);
        $this ->smarty->assign("id", $id);
        $this ->smarty->assign("pwd", $arr["pwd"]);
        $this ->smarty->assign("email", $arr["email"]);
        $this ->smarty->assign("tel", $arr["tel"]);
        $this ->smarty->display("list1.html");
    }
}
//    public function checkName(){
//        $name = $_GET["name"];
//        
//
//        $result=$this->usermodel->addUser($name);
//        if($result){
//            echo "可用";
//        }else{
//            echo"已存在";
//        }
//    }
//     public function checkPwd(){
//        $pwd = $_GET["pwd"];
//        
//
//        $result=$this->usermodel->addUser($pwd);
//        if($result){
//            echo "密码不正确";
//        }else{
//            echo"请继续下一步";
//        }
//    }
//     public function checkNick_name(){
//        $nick_name = $_GET["nick_name"];
//
//        $result=$this->usermodel->addUser($nick_name);
//        if($result){
//            echo "可用";
//        }else{
//            echo"已存在";
//        }
//    }
//    public function checkEmail(){
//        $email = $_GET["email"];
//
//        $result=$this->usermodel->addUser($email);
//        if($result){
//            echo "可用";
//        }else{
//            echo"已存在";
//        }
//    }
//    public function checkTel(){
//        $tel = $_GET["tel"];
//
//        $result=$this->usermodel->addUser($tel);
//        if($result){
//            echo "可用";
//        }else{
//            echo"已存在";
//        }
//    }
